/**
 * Filename: BaseFragment.java
 *
 * @author Firefly
 * @contact postfirefly@163.com
 * @time 2016/2/29 17:54
 */
package com.github.postsanf.yinian;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.Toast;

import com.github.postsanf.yinian.utils.Logger;
import com.github.postsanf.yinian.utils.ToastUtils;
import com.google.gson.Gson;
import com.litesuits.http.HttpConfig;
import com.litesuits.http.LiteHttp;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Fragment基类初始化操作
 */
public class BaseFragment extends Fragment {
    protected String TAG;                        // 标识
    protected BaseApplication application;                // 应用主体
    protected LiteHttp liteHttp;                    // 网络访问
    protected ImageLoader imageLoader;                // 图片加载
    protected Gson gson;                        // json利器

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TAG = this.getClass().getSimpleName();
        application = (BaseApplication) getActivity().getApplication();
        imageLoader = ImageLoader.getInstance();
        gson = new Gson();
        liteHttp = LiteHttp.newApacheHttpClient(new HttpConfig(getActivity()));
    }

    protected void intent2Activity(Class<? extends Activity> tarActivity) {
        Intent intent = new Intent(getActivity(), tarActivity);
        startActivity(intent);
    }

    // 显示Toast
    protected void showToast(String msg) {
        ToastUtils.showToast(getActivity(), msg, Toast.LENGTH_SHORT);
    }

    // 输出日志
    protected void showLog(String msg) {
        Logger.show(TAG, msg);
    }
}
